﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BookManage
{
    public partial class User3 : Form
    {
        private void Table()
        {
            dataGridView1.Rows.Clear();
            Dao dao = new Dao();
            string sql = "select * from t_lend;";
            IDataReader dc = dao.read(sql);

            while (dc.Read())
            {
                dataGridView1.Rows.Add(dc["id"].ToString(), dc["bid"].ToString(),dc["datetime"].ToString());
            }
            dc.Close();
            dao.DaoClose();
        }
        public User3()
        {
            InitializeComponent();
            Table();
        }

        private void User3_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string id = dataGridView1.Rows[0].Cells[0].Value.ToString();
            string bid = dataGridView1.Rows[0].Cells[1].Value.ToString();
            string sql = $"delete from t_lend where id = '{id}';update t_book set number = number + 1 where id = '{bid}';";
            Dao dao = new Dao();

            if(dao.Execute(sql)>1)
            {
                MessageBox.Show("还书成功");
                Table();
            }
            else
            {
                MessageBox.Show("还书失败");
                return;
            }
        }
    }
}
